package day11;

import com.mysql.jdbc.Connection;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Test1 {
    public static void main(String[] args) throws SQLException {

        Test1 test = new Test1();
    }

    public Test1() throws SQLException {
        this.lianjie();
    }

    private void lianjie() throws SQLException {

        //定义需要的对象
        Statement st = null;
        Connection conn = null;
        ResultSet rs = null;
        try {
            //1.得到连接
            conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/hr" +
                    "m?useSSL=false&useUnicode=true&characterEncoding=utf-8", "root", "123456");
            //2.创建Preparestatement,创建数据
            st = conn.createStatement();

            //3.执行语句对象
            String sql = "create database vvv";
            boolean b = st.execute(sql);
            if (b) {
                System.out.println("创建成功");
            } else {
                System.out.println("失败");
                System.out.println(b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (st != null) st.close();
                if (conn != null) conn.close();
            } catch (Exception e2) {

            }
        }
    }
}
